﻿// Decompiled with JetBrains decompiler
// Type: SP1.GradientElements
// Assembly: SP1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4A78F1E7-7FD5-407C-8917-5F99ECC43C34
// Assembly location: C:\Users\KasimGulcan\Desktop\Project\DynaCAD\bin\Debug\SP1.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Xml;

namespace SP1
{
  public static class GradientElements
  {
    public static GradientBrush LinearGradient(XmlNode xn, out string Name)
    {
      string s = "void";
      Name = "void";
      LinearGradientBrush linearGradientBrush = new LinearGradientBrush();
      linearGradientBrush.MappingMode = BrushMappingMode.RelativeToBoundingBox;
      double x1 = 1.0;
      double x2 = 1.0;
      double y1 = 2.0;
      double y2 = 2.0;
      foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap) xn.Attributes)
      {
        switch (xmlAttribute.Name)
        {
          case "id":
            Name = xmlAttribute.Value;
            continue;
          case "x1":
            x1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            continue;
          case "x2":
            x2 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            continue;
          case "y1":
            y1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            continue;
          case "y2":
            y2 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            continue;
          case "spreadMethod":
            linearGradientBrush.SpreadMethod = AtributeValueLibrary.SpreadMethodConvertor(xmlAttribute.Value);
            continue;
          case "xlink:href":
            for (int index = 0; index < DefinitionElement.GEL.Count; ++index)
            {
              if (DefinitionElement.GEL[index].Name == xmlAttribute.Value.Replace("#", ""))
                linearGradientBrush.GradientStops = DefinitionElement.GEL[index].GB.GradientStops;
            }
            continue;
          case "transformGradient":
            s = xmlAttribute.Value;
            continue;
          case "gradientUnits":
            linearGradientBrush.MappingMode = AtributeValueLibrary.MappingModeConvertor(xmlAttribute.Value);
            continue;
          default:
            continue;
        }
      }
      linearGradientBrush.StartPoint = new Point(x1, y1);
      linearGradientBrush.EndPoint = new Point(x2, y2);
      if (xn.HasChildNodes)
      {
        GradientStopCollection gradientStopCollection = new GradientStopCollection();
        foreach (XmlNode xmlNode in xn.ChildNodes)
        {
          double num1 = 1.0;
          SolidColorBrush solidColorBrush = new SolidColorBrush();
          GradientStop gradientStop = new GradientStop();
          XmlAttributeCollection attributes = xmlNode.Attributes;
          if (attributes != null)
          {
            foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap) attributes)
            {
              switch (xmlAttribute.Name)
              {
                case "offset":
                  gradientStop.Offset = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
                  continue;
                case "stop-color":
                  solidColorBrush = (SolidColorBrush) AtributeValueLibrary.GetBrush(xmlAttribute.Value);
                  continue;
                case "stop-opacity":
                  num1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
                  continue;
                case "style":
                  string str1 = xmlAttribute.Value;
                  char[] chArray1 = new char[1]
                  {
                    ';'
                  };
                  foreach (string str2 in str1.Split(chArray1))
                  {
                    char[] chArray2 = new char[1]
                    {
                      ':'
                    };
                    string[] strArray = str2.Split(chArray2);
                    if (strArray.Length == 2)
                    {
                      switch (strArray[0].Replace(" ", ""))
                      {
                        case "stop-color":
                          solidColorBrush = (SolidColorBrush) AtributeValueLibrary.GetBrush(strArray[1]);
                          continue;
                        case "stop-opacity":
                          num1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(strArray[1]) : AtributeValueLibrary.DoubleConvertor(strArray[1].Replace("%", "")) / 100.0;
                          continue;
                        default:
                          continue;
                      }
                    }
                  }
                  continue;
                default:
                  continue;
              }
            }
          }
          byte num2 = (byte) (num1 * (double) byte.MaxValue);
          byte r = solidColorBrush.Color.R;
          byte g = solidColorBrush.Color.G;
          byte b = solidColorBrush.Color.B;
          gradientStop.Color = new Color()
          {
            A = num2,
            R = r,
            G = g,
            B = b
          };
          gradientStopCollection.Add(gradientStop);
        }
        linearGradientBrush.GradientStops = gradientStopCollection;
      }
      if (s != "void")
      {
        try
        {
          TransformGroup transformGroup = TransFormLibrary.TransformGroup(s);
          linearGradientBrush.Transform = (Transform) transformGroup;
        }
        catch
        {
          Console.WriteLine("LinearGradientTransform Yapılamadı:" + s);
        }
      }
      return (GradientBrush) linearGradientBrush;
    }

    public static GradientBrush RadialGradient(XmlNode xn, out string Name)
    {
      double x1 = 0.5;
      double y1 = 0.5;
      double x2 = 0.5;
      double y2 = 0.5;
      double num1 = 0.5;
      string s = "void";
      Name = "void";
      RadialGradientBrush radialGradientBrush = new RadialGradientBrush();
      radialGradientBrush.MappingMode = BrushMappingMode.RelativeToBoundingBox;
      foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap) xn.Attributes)
      {
        switch (xmlAttribute.Name)
        {
          case "id":
            Name = xmlAttribute.Value;
            break;
          case "cx":
            x1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            break;
          case "cy":
            y1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            break;
          case "fx":
            x2 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            break;
          case "fy":
            y2 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            break;
          case "r":
            num1 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
            break;
          case "spreadMethod":
            radialGradientBrush.SpreadMethod = AtributeValueLibrary.SpreadMethodConvertor(xmlAttribute.Value);
            break;
          case "xlink:href":
            for (int index = 0; index < DefinitionElement.GEL.Count; ++index)
            {
              if (DefinitionElement.GEL[index].Name == xmlAttribute.Value.Replace("#", ""))
                radialGradientBrush.GradientStops = DefinitionElement.GEL[index].GB.GradientStops;
            }
            break;
          case "gradientTransform":
            s = xmlAttribute.Value;
            break;
          case "gradientUnits":
            radialGradientBrush.MappingMode = AtributeValueLibrary.MappingModeConvertor(xmlAttribute.Value);
            break;
        }
        radialGradientBrush.Center = new Point(x1, y1);
        radialGradientBrush.RadiusX = num1;
        radialGradientBrush.RadiusY = num1;
        radialGradientBrush.GradientOrigin = new Point(x2, y2);
      }
      if (xn.HasChildNodes)
      {
        GradientStopCollection gradientStopCollection = new GradientStopCollection();
        foreach (XmlNode xmlNode in xn.ChildNodes)
        {
          double num2 = 1.0;
          SolidColorBrush solidColorBrush = new SolidColorBrush();
          GradientStop gradientStop = new GradientStop();
          foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap) xmlNode.Attributes)
          {
            switch (xmlAttribute.Name)
            {
              case "offset":
                gradientStop.Offset = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
                continue;
              case "stop-color":
                solidColorBrush = (SolidColorBrush) AtributeValueLibrary.GetBrush(xmlAttribute.Value);
                continue;
              case "stop-opacity":
                num2 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
                continue;
              case "style":
                string str1 = xmlAttribute.Value;
                char[] chArray1 = new char[1]
                {
                  ';'
                };
                foreach (string str2 in str1.Split(chArray1))
                {
                  char[] chArray2 = new char[1]
                  {
                    ':'
                  };
                  string[] strArray = str2.Split(chArray2);
                  if (strArray.Length == 2)
                  {
                    switch (strArray[0].Replace(" ", ""))
                    {
                      case "stop-color":
                        solidColorBrush = (SolidColorBrush) AtributeValueLibrary.GetBrush(strArray[1]);
                        continue;
                      case "stop-opacity":
                        num2 = !Enumerable.Contains<char>((IEnumerable<char>) xmlAttribute.Value, '%') ? AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value) : AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value.Replace("%", "")) / 100.0;
                        continue;
                      default:
                        continue;
                    }
                  }
                }
                continue;
              default:
                continue;
            }
          }
          byte num3 = (byte) (num2 * (double) byte.MaxValue);
          byte r = solidColorBrush.Color.R;
          byte g = solidColorBrush.Color.G;
          byte b = solidColorBrush.Color.B;
          gradientStop.Color = new Color()
          {
            A = num3,
            R = r,
            G = g,
            B = b
          };
          gradientStopCollection.Add(gradientStop);
        }
        radialGradientBrush.GradientStops = gradientStopCollection;
      }
      if (s != "void")
      {
        TransformGroup transformGroup = TransFormLibrary.TransformGroup(s);
        radialGradientBrush.Transform = (Transform) transformGroup;
      }
      return (GradientBrush) radialGradientBrush;
    }
  }
}
